package com.webchat.admin.service;


import com.webchat.domain.vo.response.UserBaseResponseInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Slf4j
@Service
public class AccountRoleService {


    @Autowired
    private AccountService accountService;

    /**
     * 校验账号是否拥有权限
     *
     * @param account   用户ID
     * @param roleCode 权限CODE
     * @return
     */
    public boolean hasRole(String account, Integer roleCode) {
        if (StringUtils.isBlank(account) || roleCode == null) {
            log.error("{} not has role: {}!", account, roleCode);
            return false;
        }
        UserBaseResponseInfoVO accountInfo = accountService.accountInfo(account);
        Assert.isTrue(accountInfo != null, "无权限");
        return roleCode.equals(accountInfo.getRoleCode());
    }

}
